//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================



using System;
using System.Windows.Forms;

namespace GuidanceExplorer.Model
{
    [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = true)]
    public class MenuItemAttribute : Attribute
    {
        #region Private members

        /// <summary>
        /// The caption of the menu item.
        /// </summary>
        private string _menuItemName;

        /// <summary>
        /// The caption of the menu item when multiple items are selected
        /// </summary>
        private string _multipleSelectionMenuItemName;

        /// <summary>
        /// The name of the command that will be executed when the menu is selected.
        /// </summary>
        private string _commandName;

        /// <summary>
        /// The position of the menu item.
        /// </summary>
        private int _position;

        /// <summary>
        /// The type of the condition for displaying this menu item.
        /// </summary>
        private Type _conditionType;

        /// <summary>
        /// The cached instance of the condition.
        /// </summary>
        private IMenuItemCondition _condition;

        /// <summary>
        /// The type of the sub-menu provider for this item.
        /// </summary>
        private Type _menuItemsProviderType;

        /// <summary>
        /// The cached instance of the sub-menu provider for this item.
        /// </summary>
        private IMenuItemsProvider _menuItemsProvider;

        /// <summary>
        /// Shortcut keys
        /// </summary>
        private Keys _shortCutKeys;

        #endregion

        public MenuItemAttribute(int position, string menuItemName, string commandName, Keys shortCut)
        {
            this._menuItemName = menuItemName;
            this._commandName = commandName;
            this._position = position;
            this._shortCutKeys = shortCut;
        }

        public MenuItemAttribute(int position, string menuItemName, string multipleSelectionName, string commandName, Keys shortCut)
            : this(position, menuItemName, commandName, shortCut)
        {
            _multipleSelectionMenuItemName = multipleSelectionName;
        }

        public MenuItemAttribute(int position, string menuItemName, string commandName, Type conditionType, Keys shortCut)
        {
            this._menuItemName = menuItemName;
            this._commandName = commandName;
            this._conditionType = conditionType;
            this._position = position;
            this._shortCutKeys = shortCut;
        }

        public MenuItemAttribute(int position, string menuItemName, string multipleSelectionName, string commandName, Type conditionType, Keys shortCut)
            : this(position, menuItemName, commandName, conditionType, shortCut)
        {
            _multipleSelectionMenuItemName = multipleSelectionName;
        }

        public MenuItemAttribute(int position, string menuItemName, string commandName, Type conditionType, Type menuItemsProviderType, Keys shortCut)
        {
            this._menuItemName = menuItemName;
            this._commandName = commandName;
            this._conditionType = conditionType;
            this._position = position;
            this._menuItemsProviderType = menuItemsProviderType;
            this._shortCutKeys = shortCut;
        }

        public MenuItemAttribute(int position, string menuItemName, string multipleSelectionName, string commandName, Type conditionType, Type menuItemsProviderType, Keys shortCut)
            : this(position, menuItemName, commandName, conditionType, menuItemsProviderType, shortCut)
        {
            _multipleSelectionMenuItemName = multipleSelectionName;
        }

        #region Public properties

        /// <summary>
        /// The caption of the menu item.
        /// </summary>
        public string MenuItemName
        {
            get { return _menuItemName; }
            set { _menuItemName = value; }
        }

        /// <summary>
        /// The name of the command that will be executed when the menu is selected.
        /// </summary>
        public string CommandName
        {
            get { return _commandName; }
            set { _commandName = value; }
        }

        /// <summary>
        /// The position of the menu item.
        /// </summary>
        public int Position
        {
            get { return _position; }
            set { _position = value; }
        }

        /// <summary>
        /// The caption of the menu item when multiple items are selected
        /// </summary>
        public string MultipleSelectionMenuItemName
        {
            get { return _multipleSelectionMenuItemName; }
            set { _multipleSelectionMenuItemName = value; }
        }

        /// <summary>
        /// The type of the condition for displaying this menu item.
        /// </summary>
        public Type ConditionType
        {
            get { return _conditionType; }
            set { _conditionType = value; }
        }

        /// <summary>
        /// The cached instance of the condition.
        /// </summary>
        public IMenuItemCondition Condition
        {
            get
            {
                if (_condition == null && _conditionType != null)
                {
                    _condition = Activator.CreateInstance(_conditionType) as IMenuItemCondition;
                }
                return _condition;
            }
        }

        /// <summary>
        /// The type of the sub-menu provider for this item.
        /// </summary>
        public Type MenuItemsProviderType
        {
            get { return _menuItemsProviderType; }
            set { _menuItemsProviderType = value; }
        }

        public Keys ShortCutKeys
        {
            get { return _shortCutKeys; }
            set { _shortCutKeys = value; }
        }

        /// <summary>
        /// The cached instance of the sub-menu provider for this item.
        /// </summary>
        public IMenuItemsProvider MenuItemsProvider
        {
            get
            {
                if (_menuItemsProvider == null && _menuItemsProviderType != null)
                {
                    _menuItemsProvider = Activator.CreateInstance(_menuItemsProviderType) as IMenuItemsProvider;
                }
                return _menuItemsProvider;
            }
        }

        #endregion
    }

}

